package com.juc.completionService.completionService5;

import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorCompletionService;
import java.util.concurrent.Executors;

public class Run2 {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		MyCallableA callableA = new MyCallableA();
		MyCallableB callableB = new MyCallableB();
		Executor executor = Executors.newSingleThreadExecutor();
		CompletionService csRef = new ExecutorCompletionService<>(executor);
		csRef.submit(callableA);//先执行A
		csRef.submit(callableB);//后执行B
		for (int i = 0; i < 2; i++) {
			System.out.println("zzzzzzzzzzzzzzzz  " + csRef.take().get());
		}
		System.out.println(" main end! ");
	}
}
